package com.platform.hjt.crm.service;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.hjt.tools.code.PinYinHelper;
import com.hjt.tools.dao.Page;
import com.hjt.tools.dao.PropertyFilter;
import com.hjt.tools.date.DateCreator;
import com.platform.hjt.base.controller.ReturnBody;
import com.platform.hjt.base.service.BaseService;
import com.platform.hjt.crm.dao.CrmCustomerInfoDAO;
import com.platform.hjt.crm.model.CrmCustomerInfo;

@Service
public class CrmCustomerInfoService extends BaseService{

	@Resource
	private CrmCustomerInfoDAO crmCustomerInfoDAO;
	
	public ReturnBody saveCrmCustomerInfo(CrmCustomerInfo crmCustomerInfo){
		PinYinHelper pinYinHelper = new PinYinHelper();
		crmCustomerInfo.setShortPinyin(pinYinHelper.getStringPinYin(crmCustomerInfo.getCustomerName(), true));
		crmCustomerInfo.setFullPinyin(pinYinHelper.getStringPinYin(crmCustomerInfo.getCustomerName(), false));
		
		if(StringUtils.isNotBlank(crmCustomerInfo.getCrmCustomerInfoId())){
			crmCustomerInfoDAO.updatePerproties(crmCustomerInfo);
			return  new ReturnBody(true, "更新成功");
		}else{
			crmCustomerInfo.setIsDel(false);
			crmCustomerInfo.setSysCompanyInfo(getSessionSysCompanyInfo());
			crmCustomerInfo.setSysUserInfo(getSessionUserInfo());
			crmCustomerInfo.setCreateTime(DateCreator.getCurrentTime());
			crmCustomerInfoDAO.saveJ(crmCustomerInfo);
			return  new ReturnBody(true, "添加成功");
		}
	}
	
	public ReturnBody delCrmCustomerInfo(CrmCustomerInfo crmCustomerInfo){
		crmCustomerInfo.setIsDel(true);
		crmCustomerInfoDAO.updatePerproties(crmCustomerInfo);
		return  new ReturnBody(true, "删除成功");
	}
	
	public Page<CrmCustomerInfo> getCrmCustomerInfoList(Page<CrmCustomerInfo> page, List<PropertyFilter> propertyFilterList){
		return crmCustomerInfoDAO.findPage(page, propertyFilterList);
	}
	
	public List<CrmCustomerInfo> getCrmCustomerInfoList(List<PropertyFilter> filters){
		return crmCustomerInfoDAO.find(filters);
	}
	
	public CrmCustomerInfo getCrmCustomerInfo(List<PropertyFilter> filters){
		return crmCustomerInfoDAO.findUniqueBy(filters);
	}
	
	public CrmCustomerInfo getCrmCustomerInfo(String propertyName, Object value){
		return crmCustomerInfoDAO.findUniqueBy(propertyName, value);
	}
	
}
